//
//  WaitForTestViewController.m
//  MIDI
//
//  Created by E.M.Game on 15/9/30.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "WaitForTestViewController.h"
#import "UIViewController+NavItem.h"
#import "AppConfig.h"
#import "WaiteForTestCell.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "QXNetWorkTool.h"
#import "TestDetailModel.h"
#import "PrepareGuideViewController.h"
#import "CommFunc.h"


@interface WaitForTestViewController ()<UITableViewDelegate , UITableViewDataSource,
                                        QXNetWorkToolDelegate>

@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (nonatomic , copy) NSString * myTitle;
@property (nonatomic , strong) TestDetailModel *model;
@property (nonatomic , strong) WaiteForTestCell *myCell;

@end

@implementation WaitForTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self config];
    
    self.myTableView.showsVerticalScrollIndicator = NO;
}

- (void)config
{
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    QXNetWorkTool *tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName:ExamDetailInterface andParameter:@[@{@"exam_id":self.exam_id}] tag:1];
}

- (void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
}

- (void)GetSuccessMessage:(id)message andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    NSString *mes = message;
    
    switch (tag)
    {
        case 1:
            [MBProgressHUD showSuccess:mes toView:self.view];
            break;
    }
}

-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    if (Response == nil)
    {
        return;
    }
    switch (tag)
    {
        case 1:
        {
            for (NSDictionary *dic in Response)
            {
                self.model = [TestDetailModel TestDetailWithDict:dic];
                
                break;
            }
            [self.myTableView reloadData];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [self configNavigationItem];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self configNavigationItem];
}

-(void) configNavigationItem
{
    [self.navigationController.navigationBar setBarTintColor:MIDIColorOfNavigationBar];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationItem.title = self.title;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],UITextAttributeFont,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
}

#pragma mark tableView datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.myCell) {
        return [self.myCell getHeight];
    }
    
    return 455;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.myCell = nil;
    NSString *identifier = @"WaitForTestCellTableViewCell";
    self.myCell = [self.myTableView dequeueReusableCellWithIdentifier:identifier];
    
    if(self.myCell == nil)
    {
        self.myCell = [WaiteForTestCell loadFromXib];
    }
    
    if (self.myCell && self.model)
    {
        self.myCell.contentView.hidden = NO;
        [self configCell:self.myCell];
    }
    
    return self.myCell;
}

#pragma mark - Table View Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

-(void)configCell : (WaiteForTestCell *)mycell
{
    if ([self.model.major_name isEqualToString:@"音乐基础"])
    {
        mycell.testItemImg.image = [UIImage imageNamed:@"Img_myTestStatus_musicBase"];
    }
    else if ([self.model.major_name isEqualToString:@"爵士鼓"])
    {
        mycell.testItemImg.image = [UIImage imageNamed:@"img_myTestStatus_jueshigu"];
    }
    else if ([self.model.major_name isEqualToString:@"电吉他"])
    {
        mycell.testItemImg.image = [UIImage imageNamed:@"img_myTestStatus_dianjita"];
    }
    else if ([self.model.major_name isEqualToString:@"电贝司"])
    {
        mycell.testItemImg.image = [UIImage imageNamed:@"img_myTestStatus_dianbeisi"];
    }
    
    NSString *str = @"地点:  ";
    
    mycell.testNameLb.text = self.model.major_name;
    if ([mycell.testNameLb.text isEqualToString:@"音乐基础"])
    {
        mycell.testNameLb.text = @"音乐理论";
    }
    
    if (self.model.exam_site_name)
    {
        mycell.addrLb.text = [str stringByAppendingString:self.model.exam_site_name];
    }
    mycell.testTimeLb.text = self.model.exam_time;
    
    if (self.model.grade_num)
    {
        if ([mycell.testNameLb.text isEqualToString:@"音乐理论"])
        {
            mycell.levelLb.text = [CommFunc getMusicBaseLevel:self.model.grade_num];
        }
        else
        {
            mycell.levelLb.text = [self.model.grade_num stringByAppendingString:@"级"];
        }
    }
    mycell.phoneNumber.text = self.model.tel;
    mycell.descLb.text = self.model.detail;
    
    [mycell.button addTarget:self action:@selector(prepare:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)prepare:(UIButton *)sender
{
    //备考
    [self.navigationController pushViewController:
     [PrepareGuideViewController create] animated:YES];
}


@end


















